(function(){

	phnq.dom =
	{
		getElementsByClassName: function(clsName, startElmnt)
		{
			startElmnt = startElmnt || document;
			
			// Try with native getElementsByClassName() first.
			if(startElmnt.getElementsByClassName)
			{
				var elmnts = [];
				var eList = startElmnt.getElementsByClassName(clsName);
				var len = eList.length;
				for(var i=0; i<len; i++)
				{
					if(eList[i])
						elmnts.push(eList[i]);
				}
				return elmnts;
			}
			else // Use DOM for IE
			{
				var re = new RegExp("(^|\\s)"+clsName+"(\\s|$)");
				var elmnts = [];
				var allElmnts = startElmnt.getElementsByTagName("*");
				var len = allElmnts.length;
				for(var i=0; i<len; i++)
				{
					var elmnt = allElmnts[i];
					if(re.test(elmnt.className))
						elmnts.push(elmnt);
				}
				return elmnts;
			}
		},
		
		addClass: function(elmnt, name)
		{
			var className = elmnt.className;
			if(className)
				className += " ";
			
			className += name;
			
			elmnt.className = className;
		},
		
		removeClass: function(elmnt, name)
		{
			if(elmnt && elmnt.className)
			{
				var classes = [];
				var currentClasses = elmnt.className.split(" ");
				var len = currentClasses.length;
				for(var i=0; i<len; i++)
				{
					if(currentClasses[i] != name)
						classes.push(currentClasses[i]);
				}
				elmnt.className = classes.join(" ");
			}
		},
		
		getClasses: function(elmnt)
		{
			return elmnt ? (elmnt.className||"").split(" ") : null;
		},
		
		isExposed: function(elmnt)
		{
			var body = document.body;
			elmnt = elmnt.parentNode;
			while(elmnt && elmnt != body)
			{
				if(elmnt.style && (elmnt.style.display == "none"))
					return false;

				elmnt = elmnt.parentNode;

				if(!elmnt || elmnt.nodeType != 1)
					return false;
			}
			return true;
		}
	};
	
})();
